﻿/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2019/9/7
 * Time: 11:27
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;

namespace QStarter
{
	/// <summary>
	/// Description of IconTools.
	/// </summary>
	public class IconTools
	{	
		public static Bitmap GetIcon(string fileName, int size)
		{
			Bitmap result = null;
			
			IntPtr[] hIcons = new IntPtr[1];
//			获取第一个图标组中的指定大小图标
			int iconCount = NativeMethods.PrivateExtractIcons(fileName, 0, size, size, hIcons, null, 1, 0);
			if (iconCount > 0)
			{
				result = Icon.FromHandle(hIcons[0]).ToBitmap();
				NativeMethods.DestroyIcon(hIcons[0]);
			}
			
			return result;
		}
	}
}
